<!--
 * @Descripttion: 
 * @version: 
 * @Author: wtzhang
 * @Date: 2021-08-05 13:15:06
 * @LastEditors: wtzhang
 * @LastEditTime: 2021-08-06 15:40:16
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app"></div>
  <script src="../js/old_version/react.development.js"></script>
  <script src="../js/old_version/react-dom.development.js"></script>
  <script src="../js/old_version/babel.min.js"></script>
  <script src="../js/old_version/prop-types.js"></script>
  <script type="text/babel">
    // 创建虚拟dom, 类组件式
    class Person extends React.Component {
      // 对props中的属性值进行类型限制和必要性限制
      static propTypes = {
        // name: React.PropTypes.string // V15.5 已弃用
        name: PropTypes.string.isRequired,
        age: PropTypes.number.isRequired,
        sex: PropTypes.string,
        speek: PropTypes.func
      }
      // 指定默认标签属性值
      static defaultProps = {
        sex: '其他',
        age: 18,
        name: '--'
      }

      render() {
        console.log(this);
        const { name, age, sex } = this.props
        // this.props.name = 'rose' // Error: Cannot assign to read only property 'name' of object '#<Object>'
        return (
          <ul>
            <li>{this.props.name}</li>
            <li>{this.props.age}</li>
            <li>{this.props.sex}</li>
            <hr />
            <li>{name}</li>
            <li>{age}</li>
            <li>{sex}</li>
          </ul>
        )
      }
    }
    // 渲染到页面
    // ReactDOM.render(虚拟DOM, 容器)
    // ReactDOM.render(<Person name="jack" age={18}" speek = {speek} />, document.getElementById('app'))
    // props批量传递数据（传递标签属性）
    let obj = { name: 'jack', age: 18, speek }
    // ReactDOM.render(虚拟DOM, 容器)
    ReactDOM.render(<Person {...obj} />, document.getElementById('app'))

    function speek() {
      console.log('hello！');
    }
  </script>
</body>

</html>